﻿using Max.PH5_2008A.ShoppingCode.Domain;
using Max.PH5_2008A.ShoppingCode.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH5_2008A.ShoppingCode.API.Controllers.NewProduct
{
    /// <summary>
    /// 
    /// </summary>
    [Route("new/product/sku")]
    [ApiController]
    public class NewProductSKUController : BaseController<NewProductSKUEntity>
    {

        Microsoft.AspNetCore.Hosting.IWebHostEnvironment env;

        INewProductSKUService _service;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="service"></param>
        public NewProductSKUController(INewProductSKUService service) : base(service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取SKU的明细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public IActionResult GetSKUDetailInfoById(string id)
        {
            if (string.IsNullOrEmpty(id))
                return BadRequest("参数不合法");

            var result = _service.GetSKUDetailInfoById(id);

            return Ok(result);
        }


        private bool UploadFile()
        {
            var files = Request.Form.Files;//获取请求所有文件
            if (files == null)
                return false;
            var file = files[0];

            #region 判断文件

            //判断文件大小
            var filelength = file.Length;//文件长度
            //假设判断不超过1MB
            //1MB = 1024KB ,1KB = 1024Byte

            if (filelength > 1 * 1024 * 1024)
                return false;

            //判断文件格式
            //file.FileName.To.EndsWith(".jpg")
            //System.IO.Path.GetExtension(file.FileName).Equals(".jpg")

            #endregion
            var wwwroot = env.ContentRootPath;
            var path = "wwwroot/temp/" + file.FileName; //不建议直接这个wwwroot


            return true;
        }
    }
}
